#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
python 学习
"""

__author__ = 'hubert'

from datetime import datetime
import random


# 读文件1
def read_file(filepath):
    with open(filepath, 'r') as f:
        for line in f.readlines():
            # 把末尾的'\n'删掉
            print(line.strip())

# 读文件2
def read_file2(filepath):
    with open(filepath, 'rb') as f:
        line = f.readline()
        while line is not None and line != '':
            print(line.strip())
            line = f.readline()

# 写文件
def write_file(filepath):
    with open(filepath, 'w') as f:
        f.write("写入内容")

# 从一个文件读取内容写入另外一个文件
def read_write(file1, file2) :
    with open(file1, 'r') as f:
        line = f.readline()
        with open(file2, 'w') as f2:
            while line is not None and line != '':
                f2.write(line.strip()+"\n")
                line = f.readline()

if __name__ == '__main__':

    fpth = 'E:/home/logs/cps/common-all.log'
    fpth2 = 'C:/data/git/doc_hubert/doc/05项目/机顶盒抓包/json.txt'
    read_file2(fpth2)
    # write_file(fpth2)
    # read_write(fpth, fpth2)
